
.text

fib:
	push bp
	addi bp, sp, 0

	load r1, bp, 8
	addi r2, r0, 1

	cmp r1, r2
	jeq ret_um

	cmp r1, r0
	jeq ret_zero

	addi r1, r1, -1
	push r1
	call fib
	pop r1

	addi r2, rv, 0
	push r2

	addi r1, r1, -1
	push r1
	call fib
	addi sp, sp, 4
	pop r2

	add rv, rv, r2

	jmp epilogue

ret_um:
	addi rv, r0, 1
	jmp epilogue

ret_zero:
	addi rv, r0, r0

epilogue:
	addi sp, bp, 0
	pop bp

	ret

__start:
	addi r1, r0, query
	push r1
	pushi 1
	syscall
	addi sp, sp, 8

	pushi 2
	syscall
	addi sp, sp, 4

	push rv
	call fib
	addi sp, sp, 4

	addi r1, r0, result
	push r1
	pushi 1
	syscall
	addi sp, sp, 8

	push rv
	pushi 0
	syscall
	addi sp, sp, 8

	addi r1, r0, nl
	push r1
	pushi 1
	syscall
	addi sp, sp, 8

	stop

.data
	query:	"Digite o numero para a serie de Fibonacci: "
	result:	"Resultado = "
	nl:		"\n"
